<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header('项目方案列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row">
    <div class="col-sm-12">
      <form id="plan-form">
        <input type="hidden" id="projectId" name="projectId" th:value="${projectId}">
      </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
      <a class="btn btn-success" onclick="add()" shiro:hasPermission="project:projectPlan:add">
        <i class="fa fa-plus"></i> 添加菌剂
      </a>
      <a class="btn btn-primary" onclick="addDescription()" shiro:hasPermission="project:projectPlan:add">
        <i class="fa fa-plus"></i> 添加备注
      </a>
      <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="project:projectPlan:remove">
        <i class="fa fa-remove"></i> 删除
      </a>
      <a class="btn btn-warning" onclick="closeItem()">
        <i class="fa fa-reply-all"></i> 关闭
      </a>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
  </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
  var editFlag = [[${@permission.hasPermi('project:projectPlan:edit')}]];
  var removeFlag = [[${@permission.hasPermi('project:projectPlan:remove')}]];
  var prefix = ctx + "project/projectPlan";

  $(function () {
    var options = {
      url: prefix + "/plan",
      createUrl: prefix + "/add/{id}",
      createDescriptionUrl: prefix + "/addDescription/{id}",
      updateUrl: prefix + "/edit/{id}",
      removeUrl: prefix + "/remove",
      showFooter: true,
      modalName: "项目方案",
      columns: [{
        checkbox: true
      },
        {
          field: 'planId',
          title: '项目方案ID',
          visible: false
        },
        {
          field: 'microbialName',
          title: '菌剂名称'
        },
        {
          field: 'planCycle',
          title: '周期'
        },
        {
          field: 'planDosage',
          title: '用量'
        },
        {
          field: 'planPrice',
          title: '预计费用(元)',
          footerFormatter: function (value) {
            var sumPrice = 0;
            for (var i in value) {
              sumPrice += parseFloat(value[i].planPrice);
            }
            return "指导价格：" + sumPrice + "元";
          }
        },
        {
          title: '操作',
          align: 'center',
          formatter: function (value, row, index) {
            var actions = [];
            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.planId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.planId + '\')"><i class="fa fa-remove"></i>删除</a>');
            return actions.join('');
          }
        }]
    };
    $.table.init(options);
  });

  function queryParams(params) {
    var search = $.table.queryParams(params);
    search.projectId = $("#projectId").val();
    return search;
  }

  function add() {
    $.operate.add($("#projectId").val());
  }

  function addDescription() {
    const url = prefix + '/addDescription/' + $("#projectId").val();
    $.modal.open("项目方案描述", url);
  }
</script>
</body>
</html>